//
//  lxWeiBoEntity.m
//  luodansc
//
//  Created by 倫 星 on 2012/11/06.
//  Copyright (c) 2012年 方正株式会社. All rights reserved.
//

#import "lxWeiBoEntity.h"

@implementation lxWeiBoEntity
@synthesize image = _image;
@synthesize url = _url;
@synthesize text = _text;

- (id)init {
	self = [super init];
	if (self != nil) {
        _image = [UIImage imageNamed:@"no-image.png"];
        _url = nil;
        _text = nil;
	}
	return self;
}


- (BOOL)setEntity:(NSDictionary *)dictionary {
    BOOL result = [super setEntity:dictionary];
    if (NO == result) {
        return NO;
    }
    
    NSString *goods_img = [lxStringUtility nil2String:[dictionary objectForKey:@"goods_img"]];
    if (nil != goods_img) {
        NSString *str_url = [NSString stringWithFormat:@"%@%@", web_root, goods_img];
        NSURL *image_goods_img_url = [NSURL URLWithString:str_url];
        NSData *date = [NSData dataWithContentsOfURL:image_goods_img_url];
        _image = [UIImage imageWithData:date];
    }
    
    _url = [NSURL URLWithString:web_root_mobile];
    
    NSString *goods_name = [lxStringUtility nil2String:[dictionary objectForKey:@"name"]];
    NSString *message = NSLocalizedString(@"message_text", nil);
    
    NSString *money = NSLocalizedString(@"money", nil);
    float f_shop_price = [[dictionary objectForKey:@"shop_price"] floatValue];
    
    NSString *str_shop_price = [lxStringUtility stringTrim:[NSString stringWithFormat:@"%10.2f", f_shop_price]];
    if (YES == [lxStringUtility isNil:str_shop_price]) {
        str_shop_price = @"0";
    }
    NSString *shop_price = [NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"shop_price", nil), str_shop_price, money];

    _text = [NSString stringWithFormat:@"%@%@%@", goods_name, message, shop_price];
    
    return YES;
}

- (BOOL)setEntity:(NSString *)goods_img goods_name:(NSString *)goods_name f_shop_price:(float)f_shop_price {
    [goods_img retain];
    [goods_name retain];
    if (nil != goods_img) {
        NSString *str_url = [NSString stringWithFormat:@"%@%@", web_root, goods_img];
        NSURL *image_goods_img_url = [NSURL URLWithString:str_url];
        NSData *date = [NSData dataWithContentsOfURL:image_goods_img_url];
        _image = [UIImage imageWithData:date];
    }
    
    _url = [NSURL URLWithString:web_root_mobile];
    
    NSString *message = NSLocalizedString(@"message_text", nil);
    
    NSString *money = NSLocalizedString(@"money", nil);
    
    NSString *str_shop_price = [lxStringUtility stringTrim:[NSString stringWithFormat:@"%10.2f", f_shop_price]];
    if (YES == [lxStringUtility isNil:str_shop_price]) {
        str_shop_price = @"0";
    }
    NSString *shop_price = [NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"shop_price", nil), str_shop_price, money];
    
    _text = [NSString stringWithFormat:@"%@%@%@", goods_name, message, shop_price];
    
    return YES;
}
@end
